<?php
include('rootlogin.php');
//include('../../incsession.php');
session_start();
$level=1;
if($_POST['submit']=="submit"){
	$i=1;
	$number=$_POST['VC'];
	$num=$_POST['num'];
	
	
	$query = "SELECT vocab FROM video WHERE topicid=".$_SESSION['topic']." AND level=".$level;
	$result = mysql_query($query,$user_con);
	
	$row = mysql_fetch_array($result);
	$name=$row['vocab'];
	$path="../../vocab/".$name;
	$file=fopen($path, "w");
	fclose($file);
	$file=fopen($path, "a");
	while($i <= $number+$num)
	{	
		if($_POST['vocab'.$i]!='' && $_POST['vocab'.$i]!=' '){			
			$content=$_POST['vocab'.$i]."\r\n";
			fwrite($file, $content);
		}
		$i++;
	}
	header("location: page.php");	
}
if(!isset($_POST['VC'])){
			$VC=0;
			$flag=1;
}
else if($_POST['submit']=='add'){
			$VC=$_POST['VC'];
			$VC++;
			$flag=0;
}/*
else{
	
}*/
?>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../framestyle.css" type="text/css" media="screen">
<style type="text/css">

</style>
</head>


<body>
<div id="wrapper">
<div id="title">Online Listening Comprehension Program</div>

<div id="main">
<hr/>
<div id="title2">FOR EASY LEVEL: VOCABULARY</div>
<hr/>
<br><br>
<form method = POST action="vocab1.php" >
<?php
	
	
	
	$query="SELECT * FROM video WHERE topicid=".$_SESSION['topic']." AND level=".$level;
	$result = mysql_query($query,$user_con);
	$row = mysql_fetch_array($result);
	$name=$row['vocab'];
	$path="../../vocab/".$name;
	$file=fopen($path, "r");
	$i=0;
	while($vocab[$i]=fgets($file))
	{	
		$vocab[$i] = substr($vocab[$i], 0, -2);
		$i++;
	}
	echo "<table>";
	$num=$i;
	$i=1;
	while($i<=$num){
		if($flag==1){
			$voc=$vocab[$i-1];
		}else{
			$voc=$_POST['vocab'.$i];
		}
		echo "<tr><td align='right'>".$i.". ";
		echo '<td><input class="area medium" type="text" name="vocab'.$i.'" value="'.$voc.'"><tr><td><td>';	
		$i++;	
	}

	fclose($file);
	echo "<input type='hidden' name='num' value=".$num.">";

while($i<=$VC+$num){
	echo "<tr><td align='right'>".$i.". ";
	echo '<td><input class="area medium" type="text" name="vocab'.$i.'" value="'.$_POST["vocab".$i].'"><tr><td><td>';	
	$i++;
	
}

echo "</table><input type='hidden' name='VC' value=".$VC.">";

?>


<div class="btn_right"><input type="submit" name = "submit" value = "add"></div><br>
<div class="btn_right"><input type="submit" name = "submit" value = "submit"></div>
</form>
</div>
</div>
</body>

